var path = require('path')
var webpack = require('webpack');
var ExtractTextPlugin = require("extract-text-webpack-plugin");
var HtmlWebpackPlugin = require('html-webpack-plugin');
var projectRoot = path.resolve(__dirname, './');
var config = require('./config');
var utils = require('./utils');
module.exports = {
    //devtool: 'eval-source-map',
    entry: {
        app: ['./dev-client', "./src/main.js"]
    }, //已多次提及的唯一入口文件
    output: {
        path: config.build.assetsRoot, //打包后的文件存放的地方
        filename: utils.assetsPath("js/[name][hash:7].js"), //打包后输出文件的文件名
        chunkFilename: utils.assetsPath("js/[name][hash:7].js")
    },
    resolve: {
        extensions: ['', '.js', '.vue', '.css'],
        fallback: [path.join(__dirname, './node_modules')],
        alias: {
            'src': path.resolve(__dirname, './src'),
            'assets': path.resolve(__dirname, './public'),
            'components': path.resolve(__dirname, './src/components')
        }
    },
    module: { //在配置文件里添加JSON loader
        loaders: [{
            test: /\.json$/,
            loader: "json"
        }, {
            test: /\.scss$/,
            loader: "style!css!sass"
        }, {
            test: /\.less$/,
            loader: "style!css!less"
        }, {
            test: /\.js$/,
            loader: 'babel',
            include: projectRoot,
            exclude: /node_modules/
        }, {
            test: /\.vue$/,
            loader: 'vue'
        }, {
            test: /\.html$/,
            loader: 'vue-html'
        }, {
            test: /\.(png|jpg|gif|svg)(\?.*)?$/,
            loader: 'url',
            query: {
                limit: 1000,
                name: 'img/[name].[hash:7].[ext]'
            }
        }, {
            test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
            loader: 'url',
            query: {
                limit: 10000,
                name: 'fonts/[name].[hash:7].[ext]'
            }
        }].concat(utils.styleLoaders())
    },
    plugins: [
        // https://github.com/glenjamin/webpack-hot-middleware#installation--usage
        new webpack.optimize.OccurenceOrderPlugin(),
        new webpack.HotModuleReplacementPlugin(),
        new webpack.NoErrorsPlugin(),
        // https://github.com/ampedandwired/html-webpack-plugin
        new HtmlWebpackPlugin({
            filename: 'index.html',
            template: 'index.html',
            inject: true
        })
    ]
};
